#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>

#include "list.h"					  /* use the SimCList library */


int randi(int max)
{
	int rand_num;
	static struct random_data rand_data;
	static char rand_state[256];
	static bool initialized = FALSE;

	if (!initialized) {
		initstate_r(time(0), rand_state, sizeof(rand_state), &rand_data);
		initialized = TRUE;
	}
	random_r(&rand_data, &rand_num);
	double cof = rand_num / (RAND_MAX + 1.0);
	return (int)(max * cof);
}

int main()
{
	list *mylist;					  /* declare a list */
	int userval;
	int i,rnum;

	mylist = listCreate();		  /* initialize the list */

	printf("Insert your number: ");
	scanf("%d", &userval);

	for (i = 0; i<userval ; rnum=randi(userval), i++)
		listAddNodeTail(mylist, &rnum);	/* add an element to the list */

	printf("The list now holds %lu elements.\n", listLength(mylist));	/* get the size of the list */

	listRelease(mylist);

	return 0;
}
